package com.ccsoft.thread.service;

import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.TimeUnit;

/**
 * 2021年12月17日 08:42:27 chanchaw
 * 演示死锁
 */
@Slf4j
public class No10Deadlock {

    public static void main(String[] args) {
       Object lockA = new Object();
       Object lockB = new Object();

       new Thread(() -> {
           synchronized (lockA){
               log.info("锁定 lockA");
               synchronized (lockB){
                   log.info("锁定 lockB");
               }
           }
       },"t1").start();


        new Thread(() -> {
            synchronized (lockB){
                log.info("锁定 lockB");
                synchronized (lockA){
                    log.info("锁定 lockA");
                }
            }
        },"t2").start();
    }

}

